package com.htpro.controller;

import com.alibaba.fastjson.JSON;
import com.htpro.pojo.Film;
import com.htpro.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@CrossOrigin
@RestController
public class FilmController {
    @Autowired
    private FilmService fs;

    @GetMapping("/allFilms")
    public List<Film> allFilms() {
        List<Film> list = fs.getAllFilm();
//        String s = JSON.toJSONString(list);
//        response.getWriter().println(s);
        return list;
    }

    @GetMapping("/oneFilm/{fid}")
    public List<Film> oneFilm(@PathVariable("fid") Integer id){
        List<Film> s = fs.getOneFilm(id);
        return s;
    }

    @GetMapping("/filmByTypef/{pid}")
    public List<Film> filmByTypef(@PathVariable("pid") Integer id){
        List<Film> list = fs.getFilmByTypef(id);
        return list;
    }
    @GetMapping("/filmByhighDate")
    public List<Film> filmByDate(){
        List<Film> list = fs.gerFilmByhighDate();
        return list;
    }

    @GetMapping("/filmBylowDate")
    public List<Film> filmBylowDate(){
        List<Film> list = fs.gerFilmBylowDate();
        return list;
    }

    @GetMapping("/filmByMohuName/{fname}")
    public List<Film> filmByMohuName(@PathVariable("fname") String name){
        List<Film> list = fs.getFilmByMohuName(name);
        return list;
    }
}
